33 33 votes Given a set of $n$ distinct numbers, we would like to determine both the smallest and the largest number. Which of the following statements is TRUE? These two elements can be determined using $O\left(\log^{100}n\right)$ comparisons. $O\left(\log^{100}n\right)$ comparisons do not suffice, however these two elements can be determined using $n + O(\log n)$ comparisons. $n+O(\log n)$ comparisons do not suffice, however these two elements can be determined using $3\lceil n/2 \rceil$ comparisons. $3\lceil n/2 \rceil$ comparisons do not suffice, however these two elements can be determined using $2(n - 1)$ comparisons. None of the above. Related Questions :GATE CSE 2007 | Question: 50GATE CSE 2014 | Set 1 | Question: 39TIFR CSE 2014 | Part B | Question: 9GATE CSE 2021 | Set 1 | Question: 2 Algorithms tifr2014 algorithms maximum-minimum + – Misbah Ghaya 8.3k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments pritishc commented Dec 15, 2019 reply Follow flag The divide and conquer algorithm for finding the min and max elements of a list operates in worst case $3n/2 - 2$ comparisons. It is described in Sartaj Sahni's algorithms book. 2 2 replyShare `JEET commented Dec 15, 2019 reply Follow flag Thanks. 0 0 replyShare JashanArora commented Mar 3, 2020 reply Follow flag To find the smallest and the second smallest element (and the third smallest.. so on), it is $n + O(n)$ (See this and this) To find the maximum and the minimum element, $ceil(3n/2)-2$ 6 6 replyShare Please log in or register to add a comment.
Best answer 18 18 votes Answer will be C. To be accurate, it will need $3n/2 -2$ comparisons . Pranay Datta 1 answered Nov 20, 2015 • edited Jul 20, 2021 by soujanyareddy13 Pranay Datta 1 comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments Kiyoshi commented Jun 8, 2021 reply Follow flag It is true for n=2 in my opinion. can you tell where it is wrong?? 0 0 replyShare Kiyoshi commented Jun 8, 2021 reply Follow flag @sushmita comment, for even numbers- 1.5n-2 for odd- 3/2(n-1) Comparisons it basically keeps you away from fraction and give positive integers (positive whole numbers) . any even number multiply with .5 give whole number always. now, for even – 1.5n making whole number and in odd – (n-1) making it even and even multiply with 1.5 give whole number. 0 0 replyShare Franz Kafka commented Jan 3, 2024 reply Follow flag For odd it’ll be 3(n-2)/2 comps 1 1 replyShare Please log in or register to add a comment.
9 9 votes Similar to the approach proposed by Himanshu1 here: https://gateoverflow.in/27194/tifr2014-b-9 Construct a decision tree to determine the minimum element: $n - 1$ comparisons Maximum element can be found from the same tree as it will be the biggest element out of $\frac{n}{2}$ elements at the first level which lost the decision: $\frac{n}{2} - 1$ comparisons Therefore, the resultant number of comparisons: $3(\frac{n}{2}) - 2$, tighest bound on which is option (C). Pranav Kant Gaur answered Dec 8, 2016 Pranav Kant Gaur comment Share Follow See all 3 Comments 3 3 Comments reply Bad_Doctor commented Jan 14, 2018 reply Follow flag @pranav Kant Gaur Maximum element will at leaf na? and at leaf there are n elements so comparison should be n-1. Please clear my doubt. 0 0 replyShare kshitij commented Jan 6, 2019 reply Follow flag @Bad_Doctor Yes maximum comparison will be for leaf.But question is asking for both maximim and minimum . For maximum n-1 comparison For minimum n-1 comparison Total number of comparison=2*(n-1) If you will draw the tree you will find that the leaf node level(is the last level) needs n/2 comparison.And it is common to both minimum and maximum. So total number of comparison required=2*(n-1) -n/2 =(3/2)n-2 when n is even. 0 0 replyShare `JEET commented Dec 6, 2019 reply Follow flag https://gateoverflow.in/27194/tifr2014-b-9 This is a rather good explanation. 0 0 replyShare Please log in or register to add a comment.